package com.gxa.controller;

import com.gxa.pojo.Institutional;
import com.gxa.service.impl.InstitutionalServiceImpl;
import com.gxa.utils.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


//import org.springframework.web.bind.annotation.RequestBody;
//import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = "组织信息管理")
public class InstitutionalController {

    @Autowired
    private InstitutionalServiceImpl institutionalService;

   // @Api(tags = "组织管理")
    @PostMapping("/institutional")
    @ApiOperation("组织管理信息添加")
    @ResponseBody
    public ResponseData insertInstitutional(@ApiParam(value = "组织添加",required = true) @RequestBody Institutional institutional) {

        if (institutionalService.insertInstitutional(institutional)) {
            return new ResponseData(1, "添加成功");
        } else {
            return new ResponseData(0, "添加失败");
        }
    }

    /**
     * 添加数据
     *
     * @param pageNum 主键
     * @return 添加是否成功
     */

   // @Insert("/insert")
    @GetMapping("/selectInstitution")
    @ApiOperation(value = "组织管理信息查找",httpMethod = "POST")
    @ResponseBody
 /*   public ResponseData selectInstitutional(Institutional institutional) {
        ResponseData responseData = new ResponseData();
        if (this.institutionalService.selectInstitutional(institutional)!=null){
            responseData.setMsg("success");
        }else {
            responseData.setCode(404);
            responseData.setMsg("fail");
        }
        return responseData;
    }*/
    public ResponseData selectInstitutional(@ApiParam(value = "显示第几页",required = true) Integer pageNum,@ApiParam(value = "每页显示几条",required = true) Integer pageSize){

        if(institutionalService.selectInstitutional(pageNum,pageSize)!=null){
            return new ResponseData(1,"显示成功",institutionalService.getCount(),institutionalService.selectInstitutional(pageNum,pageSize));
        }else {
            return new ResponseData(0,"显示失败");
        }
    }

    @DeleteMapping("/deleteInstitutional")
    @ApiOperation("组织管理信息删除")
    @ResponseBody
    public ResponseData deleteInstitutional(@ApiParam(value = "要删除的名字",required = true) String institutional_name ){
        if(institutionalService.deleteInstitutional(institutional_name)){
            return new ResponseData(1,"删除成功");
        }else {
            return new ResponseData(0,"删除失败");
        }
    }
}
